Skip to content

Ref #1589: Add warning messages for migration annotation #3562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

vitorsvieira
Copy link
Contributor

Regarding #1589, this PR addresses:

  • "{symbol} has an unparsable version number..." (RefCheck:694)
  • "{symbol} has changed semantics in version..." (RefCheck:698)

Copy link
Member

@dottybot dottybot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, and thank you for opening this PR! 🎉

All contributors have signed the CLA, thank you! ❤️

Commit Messages

We want to keep history, but for that to actually be useful we have
some rules on how to format our commit messages (relevant xkcd).

Please stick to these guidelines for commit messages:

  1. Separate subject from body with a blank line
  2. When fixing an issue, start your commit message with Fix #<ISSUE-NBR>:
  3. Limit the subject line to 72 characters
  4. Capitalize the subject line
  5. Do not end the subject line with a period
  6. Use the imperative mood in the subject line ("Added" instead of "Add")
  7. Wrap the body at 80 characters
  8. Use the body to explain what and why vs. how

adapted from https://chris.beams.io/posts/git-commit

Have an awesome day! ☀️

@vitorsvieira vitorsvieira changed the title #1593: Added error message for symbol has unparsable version and for symbol has changed semantics in version #1593: Added warning messages for migration annotation Nov 26, 2017
@vitorsvieira vitorsvieira changed the title #1593: Added warning messages for migration annotation #1593: Add warning messages for migration annotation Nov 26, 2017
@nicolasstucki
Copy link
Contributor

nicolasstucki commented Nov 27, 2017

Please change the commit message to Ref #1593: Add warning messages for migration annotation

@vitorsvieira vitorsvieira changed the title #1593: Add warning messages for migration annotation Ref #1593: Add warning messages for migration annotation Nov 27, 2017
…d-changed-semantics-in-version

# Conflicts:
#	compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java
#	compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
@vitorsvieira vitorsvieira changed the title Ref #1593: Add warning messages for migration annotation Ref #1589: Add warning messages for migration annotation Nov 27, 2017
val explanation =
hl"""$migrationMessage
|
|The symbol is marked with ${"@migration"} indicating it has changed semantics
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not talk about symbols as this is a compiler internal concept, the user should not know about them. You should probably replace it with ${symbol.showLocated} or ${symbol.show}.

|
|The symbol is marked with ${"@migration"} indicating it has changed semantics
|between versions and the ${"-Xmigration"} settings is used to warn about constructs
|whose behavior may have changed since version.""".stripMargin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"may have changed since version" -> "may have changed since version change"

val explanation = {
hl"""The symbol is marked with ${"@migration"} indicating it has changed semantics
|between versions and the ${"-Xmigration"} settings is used to warn about constructs
|whose behavior may have changed since version.""".stripMargin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

hl"""${symbol.showLocated} has changed semantics in version $symbolVersion:
|$migrationVersion""".stripMargin
val explanation = {
hl"""The symbol is marked with ${"@migration"} indicating it has changed semantics
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same (symbol)

@vitorsvieira
Copy link
Contributor Author

vitorsvieira commented Nov 28, 2017

I was always curious about this annotation. Is there any reason why it is not part of the standard library? ATM, it is available only internally private[scala] final class migration(message: String, changedIn: String) extends scala.annotation.StaticAnnotation.

Just out of curiosity, Swift provides the @available attribute, that IMO is an expanded
representation of scala's @migration. Maybe a combination of @deprecated and @migration

In Swift, @available(Platform+VersionNumber*, Args*) attribute can be used to indicate the whole declaration's lifecycle, relative to certain Swift language versions or certain platforms and operating system versions. Some of its arguments:

  • unavailable(version number)
  • introduced(version number)
  • deprecated(version number)
  • obsoleted(version number)
  • message(message)
  • renamed(new name)

In scala's ecosystem, this would mean the possibility to achieve something like:
@available(JVM1_8, ScalaJS1_0, ScalaNative1_0, introduced=2.4, deprecated=2.6, obsoleted=2.10, renamed="newMethodName")

Reference: https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Attributes.html#//apple_ref/doc/uid/TP40014097-CH35-ID347

PS: Not a suggestion, just toughts ;)

false
}
if (changed)
ctx.warning(s"${sym.showLocated} has changed semantics in version $symVersion:\n${sym.migrationMessage.get}")
ctx.warning(SymbolChangedSemanticsInVersion(sym, symVersion, sym.migrationMessage.get))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you're at it. Can you move this into the match. There is no need for this changed variable.
Also, symVersion is sym.migrationVersion.get so you don't need both of them

Copy link
Contributor Author

@vitorsvieira vitorsvieira Nov 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. 1sec.

ctx.settings.Xmigration.value < v
val xMigrationValue = ctx.settings.Xmigration.value
if (sym.hasAnnotation(defn.MigrationAnnot) && xMigrationValue != NoScalaVersion) {
sym.migrationVersion.get match {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your match is not exhaustive

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

if (sym.hasAnnotation(defn.MigrationAnnot) && xMigrationValue != NoScalaVersion) {
sym.migrationVersion.get match {
case scala.util.Success(symVersion) if xMigrationValue < symVersion =>
ctx.warning(SymbolChangedSemanticsInVersion(sym, symVersion, sym.migrationMessage.get))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove sym.migrationMessage.get. It is the same as symVersion. I don't know why it was duplicated in the first place

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have to change the final message if that is ok. Currently:

${symbol.showLocated} has changed semantics in version $symbolVersion:
$migrationVersion

The migrationMessage provides either a version string or an error message from ScalaVersion.parse:

 def failure = Failure(new NumberFormatException(
      s"There was a problem parsing ${versionString}. " +
       "Versions should be in the form major[.minor[.revision]] " +
       "where each part is a positive number, as in 2.10.1. " +
       "The minor and revision parts are optional."
    ))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It cannot be a failure since you're in the Success case of the match

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

if (sym.hasAnnotation(defn.MigrationAnnot) && xMigrationValue != NoScalaVersion) {
sym.migrationVersion.get match {
case scala.util.Success(symVersion) if xMigrationValue < symVersion =>
ctx.warning(SymbolChangedSemanticsInVersion(sym, symVersion, sym.migrationMessage.get))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're missing the pos

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

|
|The ${symbol.showLocated} is marked with ${"@migration"} indicating it has changed semantics
|between versions and the ${"-Xmigration"} settings is used to warn about constructs
|whose behavior may have changed since version change.""".stripMargin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to stripMargin

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

val explanation = {
hl"""The ${symbol.showLocated} is marked with ${"@migration"} indicating it has changed semantics
|between versions and the ${"-Xmigration"} settings is used to warn about constructs
|whose behavior may have changed since version change.""".stripMargin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to stripMargin

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Contributor

@allanrenucci allanrenucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to update your submodules:

git submodule update

ctx.warning(s"${sym.showLocated} has an unparsable version number: ${ex.getMessage()}", pos)
false
ctx.warning(SymbolHasUnparsableVersionNumber(sym, ex.getMessage()), pos)
case _ => ()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove ()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

@allanrenucci allanrenucci merged commit e98ee92 into scala:master Nov 28, 2017
@vitorsvieira vitorsvieira deleted the wip/1593-symbol-with-unparsable-version-and-changed-semantics-in-version branch November 29, 2017 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants